package com.sh.data.engine.domain.shims.sql.select;

import lombok.extern.slf4j.Slf4j;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Auther: zigui.zdf @Date: 2019/9/10 09:37 @Description:
 */
@Slf4j
public class MapRowMapper extends RowMapper<Map<String, Object>> {

    @Override
    public Map<String, Object> convert(ResultSet resultSet, int rowNum) throws SQLException {
        ResultSetMetaData metaData = resultSet.getMetaData();

        Map<String, Object> rowMap = new LinkedHashMap<>();

        for (int i = 1; i <= metaData.getColumnCount(); i++) {
            rowMap.put(metaData.getColumnLabel(i), resultSet.getObject(i));
        }

        return rowMap;
    }
}
